<template>
  <div class="flex flex-col h-full">
    <searchContainer @search="getData" @reset="() => formRef.resetFields()">
      <a-form ref="formRef" class="form-style-flex" :model="formState" :colon="false" :label-col="{ style: { width: '70px' } }">
        <a-form-item name="mcbm" class="w-1/5">
          <a-input v-model:value="formState.mcbm" placeholder="员工编号/员工姓名/助记码" />
        </a-form-item>
        <a-form-item label="科室" name="ks" class="w-1/5">
          <SelectSection v-model:value="formState.ks" />
        </a-form-item>
      </a-form>
    </searchContainer>
    <a-card class="mt-2 flex-1">
      <div class="flex justify-end mb-3">
        <BaseExport type="运维" name="医师维护" code="00001189" :search-params="formState">导出</BaseExport>
      </div>
      <baseTable :loading="loading" column-code="00001189" fill :data-source="tableData" bordered :scroll="{ x: 2800 }" :pagination="pagination">
        <template #bodyCell="{ column, index, record }">
          <template v-if="column.dataIndex === 'xh'">
            {{ index + 1 }}
          </template>
          <template v-if="column.dataIndex === 'statusStr'">
            <a-tag v-if="record.status === 1" color="red">封存</a-tag>
            <a-tag v-else color="blue">正常</a-tag>
          </template>
          <template v-if="column.dataIndex === 'action'">
            <a-button type="link" size="small" @click="onClickEdit(record)"> 维护 </a-button>
          </template>
        </template>
      </baseTable>
    </a-card>
    <Edit v-model:open="editOpen" :row-data="rowData" @success="onSuceess" />
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
// import { message } from 'ant-design-vue'
// import { post } from '@/utils/request'
import searchContainer from '@/components/SearchContainer'
import baseTable from '@/components/BaseTable'
// import selectDepartment from '@/components/SelectDepartment'
import Edit from './components/Edit'

// const departmentList = ref([])
const rowData = ref({})
const editOpen = ref(false)
const formRef = ref(null)
const formState = ref({
  emplbid: '1'
})

// const getDepartmentList = async () => {
//   const { code, data } = await post('/operation/opex/getDepartmentService', {
//     mcbh: '',
//     pageNum: 1,
//     pageSize: 999
//   })
//   if (code !== 0) return
//   departmentList.value = data.map((item) => {
//     return {
//       label: item.bmmc,
//       value: item.bmbh
//     }
//   })
// }

const onClickEdit = (row = {}) => {
  editOpen.value = true
  rowData.value = { ...row }
}

const { loading, tableData, pagination, getData } = useTable({
  url: '/operation/opex/getEmpInfoList',
  immediate: true,
  params: formState.value
})

const onSuceess = () => {
  editOpen.value = false
  getData()
}
onMounted(() => {
  // getDepartmentList()
  getData()
})
</script>
<style lang="less" scoped>
.ant-picker {
  width: 100%;
}
</style>
